#!/bin/bash

# 创建必要的目录
mkdir -p /home/pyapp/workspace/cardsysTest/{backend,frontend,logs}
mkdir -p /home/pyapp/www/cardsys_test

# 设置 Python 虚拟环境
cd /home/pyapp/workspace/cardsysTest/backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install gunicorn

# 复制 Nginx 配置
cp /home/pyapp/workspace/cardsysTest/nginx_cardsys_test.conf /home/pyapp/nginx/conf/
cd /home/pyapp/nginx/conf
sed -i '/include.*nginx_cardsys_test.conf;/d' nginx.conf
echo "    include /home/pyapp/nginx/conf/nginx_cardsys_test.conf;" >> nginx.conf

# 设置权限
chmod +x /home/pyapp/workspace/cardsysTest/start_service.sh
chmod +x /home/pyapp/workspace/cardsysTest/stop_service.sh

# 重启 Nginx
/home/pyapp/nginx/sbin/nginx -s reload

# 启动后端服务
/home/pyapp/workspace/cardsysTest/start_service.sh
